package com.controller;

import com.alibaba.fastjson.JSONObject;
import com.entity.IndexWall;
import com.entity.UserInfo;
import com.entity.Wall;
import com.entity.chat.*;
import com.service.ChatmsgService;
import com.service.FriendsService;
import com.service.UserInfoService;
import com.service.WallService;
import com.util.StatusCode;
import com.vo.ResultVo;
import org.apache.commons.io.FilenameUtils;
import org.aspectj.weaver.patterns.ThisOrTargetAnnotationPointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Controller
public class LoveWellController {
	@Autowired 
	WallService wallService;
	@Autowired
	UserInfoService userInfoService;
	
	 /**
     *后台管理界面，查看审核通过的表白
     * **/
    @GetMapping("/love/audlove")
    public String AudLove (){
        return "/admin/Love/AudLove";
    }
    
    /**
     *后台管理界面，查看审核未通过的表白
     * **/
    @GetMapping("/love/Unaudlove")
    public String UnAudLove (){
        return "/admin/Love/UnAudLove";
    }
    
    /**
     *个人中心，获取表白墙信息
     * **/
    @ResponseBody
    @RequestMapping("/wall/getlovewall")
    public ResultVo foundWalls(HttpSession session){	
    	ArrayList<IndexWall> indexWalls=this.wallService.foundWalls(null);
    	ArrayList<IndexWall> indexWalls1=wallService.foundWalltoindex();
    	System.out.println(indexWalls1);
    	System.out.println(indexWalls);
    	List<ArrayList<IndexWall>> indArrayList = new ArrayList<ArrayList<IndexWall>>();
    	indArrayList.add(indexWalls1);
    	indArrayList.add(indexWalls);
    	System.out.println(indArrayList);
    	return new ResultVo(true,StatusCode.OK,"成功",indArrayList);
    }
    
    /**
     *个人中心，获取表白墙信息
     * **/
    @ResponseBody
    @RequestMapping("/user/getlovewall")
    public ResultVo getWall(HttpSession session){	
    	
    	return new ResultVo(true,StatusCode.OK,"成功",this.wallService.foundWalls((String)session.getAttribute("userid")));
    }
    
    /**
     *个人中心，发布表白墙信息
     * **/
    @ResponseBody
    @RequestMapping("/user/addlovewall")
    public ResultVo addLoveWall(@RequestBody Wall wall,HttpSession session) {
    	wall.setSuser((String) session.getAttribute("userid"));
    	this.wallService.installWall(wall);
    	ResultVo rv=new ResultVo();
    	
    	return rv;
    }
    
    /**
     *首页，展示表白墙数据接口
     * **/
    @ResponseBody
    @RequestMapping("/index/getWalllist")
    public ResultVo getWallList() {
    	ResultVo rv = new ResultVo();
    	if (this.wallService.foundWalltoindex()!=null) {
			rv.setFlag(true);
			rv.setMessage("查询成功");
			rv.setStatus(StatusCode.OK);
			rv.setData(this.wallService.foundWalltoindex());
		}else {
			rv.setFlag(false);
			rv.setMessage("系统出错");
			rv.setStatus(StatusCode.ERROR);
		}
		return rv;
    	
    }
}
